package cn.edu.cqut.test0507;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import cn.edu.cqut.test0409.Birthday;
import cn.edu.cqut.test1.Person;

public class Test2 {
	public static void main(String[] args) throws Exception {
		Person zhangsan = new Person("张三", 20);
		zhangsan.bir = new Birthday();
		Person lisi = new Person("李四", 21);
		lisi.bir = new Birthday();
		Person wangwu = new Person("王五", 22);
		wangwu.bir = new Birthday();
		File file = new File("person.dat");
		ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
		outputStream.writeObject(zhangsan);
		outputStream.writeObject(lisi);
		outputStream.writeObject(wangwu);
		outputStream.flush();
		outputStream.close();

		ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(file));
		zhangsan = (Person) inputStream.readObject();
		lisi = (Person) inputStream.readObject();
		wangwu = (Person) inputStream.readObject();
		inputStream.close();
		System.out.println(zhangsan.toString());
		System.out.println(lisi.toString());
		System.out.println(wangwu.toString());
	}
}
